package com.xty.itgroup.tech05tytex.Logic;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xty.itgroup.tech05tytex.Databean.Bean03AxisMain;
import com.xty.itgroup.tech05tytex.Databean.Bean03Company;
import com.xty.itgroup.tech05tytex.Mapper.Impl.Impl03Axis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Copyright ? 2020年 tech05tytex. All rights reserved.
 *
 * @author JinHaoNan
 * TODO: 为了共建和谐社会，请为该类写点注释吧...
 * version 1.0.0
 * @date 2020/10/10 15:23
 */
@Service
public class Logic03Axis {
    @Autowired
    private Impl03Axis axis;
    /**
     * 根据订单的品名获取订单下的配方信息
     *
     * @return
     */
    public JSONObject getLines(String project_name) {
        List<Map<String, Object>> bgf = axis.getAxisLines(project_name);
        JSONArray w = new JSONArray();
        JSONArray j = new JSONArray();
        for (Map<String, Object> b : bgf) {
            if (b.get("jw_type").toString().equals("W")) {
                w.add(b);
            } else {
                j.add(b);
            }
        }
        JSONObject json = new JSONObject();
        json.put("axis_lines_w", w);
        json.put("axis_lines_j", j);
        return json;
    }
    @Transactional
    public void addAxisCard(Bean03AxisMain bam) {
        axis.addAxisMain(bam);

        //添加经纬信息
        axis.addAxisDetail(bam.getJ_info(), "J", bam.getAxis_main_id());
        axis.addAxisDetail(bam.getW_info(), "W", bam.getAxis_main_id());
    }
    /**
     * 轴卡信息列表
     *
     * @param orderid
     * @param weavename
     * @param companyid
     * @return
     */
    public List<Map<String, Object>> listAxisCard(String orderid, String weavename, int companyid) {
        return axis.listAxisCards(orderid, weavename, companyid);
    }

    /**
     * 获取详情
     *
     * @param mainid
     * @return
     */
    public JSONObject getAxisCardDetail(int mainid) {
        JSONObject result = new JSONObject();
        result.put("axis_main", axis.getMainById(mainid));
        result.put("axis_detail", axis.getDetailByAxisId(mainid));
        return result;
    }
    /**
     * 轴卡修改
     */
    @Transactional
    public void updateAxisCard(Bean03AxisMain bam) {
        //根据main_id修改main轴卡信息

        axis.updateAxisMain(bam);
        //根据main_id 删除 detail信息
        axis.deleteAxisdetail(bam.getAxis_main_id());
        //添加detail轴卡信息
        axis.addAxisDetail(bam.getJ_info(), "J", bam.getAxis_main_id());
        axis.addAxisDetail(bam.getW_info(), "W", bam.getAxis_main_id());
    }
    @Transactional
    public void deleteById(int mainid){
        axis.deleteAxisMain(mainid);
        axis.deleteAxisdetail(mainid);
    }

    public List<Bean03Company> listCompany(String company_name){
        return axis.listCompany(company_name);
    }

}
